﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZZQFrameWork;

public class TaskItem:MonoBehaviour
{
    private Text nameText;
    private Text progressText;

    private TaskData data;

    public TaskData Data
    {
        get { return data; }
        set
        {
            data = value;
            if(data!=null)
            UpdateShow();
        }
    }

    void Awake()
    {
        nameText = transform.GetComponentByPath<Text>("Name");
        progressText = transform.GetComponentByPath<Text>("Progress");
    }

    private void UpdateShow()
    {
        if (nameText == null) nameText = transform.GetComponentByPath<Text>("Name");
        if (progressText == null) progressText = transform.GetComponentByPath<Text>("Progress");
        nameText.text = Data.name;
        progressText.text = Data.conditionDatList[0].nowCount + "/" + Data.conditionDatList[0].needCount;
    }

    public void UpdateProgress(Enum_TaskProgress type)
    {
        Debug.Log(type);
        if (type == Enum_TaskProgress.Unfinished)
        {
            progressText.text = Data.conditionDatList[0].nowCount + "/" + Data.conditionDatList[0].needCount;
        }
        else if(type==Enum_TaskProgress.Finished)
        {
            progressText.text = "已完成";
        }
        else
        {
            nameText = null;
            progressText = null;
            Data = null;
            Destroy(this.gameObject);
        }
    }
}
